#include <vector>
#include <unordered_map>

using std::vector;
using std::unordered_map;

class Solution {
public:
    int majorityElement(vector<int>& nums) {
        int ret = 0, counts = 0;
        for (int i : nums) {
            if (counts == 0) {
                ret = i;
            }
            if (i == ret) {
                counts++;
            }
            else {
                counts--;
            }
        }
        return ret;
    }
};